![@thi.ng/canvas](https://media.thi.ng/umbrella/banners-20230807/thing-canvas.svg?4b51249a)
![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)
[!NOTE]
This is one of 200 standalone projects, maintained as part
of the @thi.ng/umbrella monorepo
and anti-framework.
🚀 Please help me to work full-time on these projects by sponsoring me on
GitHub. Thank you! ❤️
About
Canvas creation & HDPI support helpers.
This package provides small frequently used helpers for HTML Canvas 2D creation
& resizing:
Status
STABLE - used in production
Search or submit any issues for this package
Note: Some functions were previously part of the
thi.ng/adapt-dpi
and
thi.ng/pixel
packages, but have been migrated to this package for better/smaller re-use...
Installation
yarn add @thi.ng/canvas
ESM import:
import * as can from "@thi.ng/canvas";
Browser ESM import:
<script type="module" src="https://esm.run/@thi.ng/canvas"></script>
JSDelivr documentation
Package sizes (brotli'd, pre-treeshake): ESM: 380 bytes
Dependencies
None
Usage examples
25 projects in this repo's
/examples
directory are using this package:
Screenshot | Description | Live demo | Source |
---|
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/blurhash.jpg) | Interactive & reactive image blurhash generator | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/canvas-recorder.png) | Self-modifying, animated typographic grid with emergent complex patterns | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-classify-point.png) | Polygon point classification (inside/boundary/outside) | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-complex-poly.png) | Shape conversions & operations using polygons with holes | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-extra-hiccup.jpg) | Embedding thi.ng/hiccup data/elements in thi.ng/geom shape hierarchies | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/geom/geom-fuzz.png) | geom-fuzz basic shape & fill examples | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-unique-edges.png) | Iterating the unique edges of a tessellation | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/grid-iterators.png) | Visualization of different grid iterator strategies | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/hiccup-canvas-basics.png) | Basic hiccup-based canvas drawing | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/ifs-fractal.jpg) | Barnsley fern IFS fractal renderer | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/pixel/pixel-basics.png) | Pixel buffer manipulations | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-dither.jpg) | Showcase of various dithering algorithms | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-indexed.jpg) | Image dithering and remapping using indexed palettes | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-normal-map.jpg) | Normal map creation/conversion basics | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-waveform.jpg) | RGB waveform image analysis | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/poly-subdiv.jpg) | Animated, iterative polygon subdivisions & visualization | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/porter-duff/porter-duff2.png) | Port-Duff image compositing / alpha blending | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rasterize-blend.jpg) | Steering behavior drawing with alpha-blended shapes | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/soa-ecs-100k.png) | Entity Component System w/ 100k 3D particles | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/unbiased-normals.png) | Visual comparison of biased vs. unbiased normal vectors projected on the surface of a sphere | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-cubemap.jpg) | WebGL cube maps with async texture loading | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-grid.jpg) | WebGL instancing, animated grid | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-msdf.jpg) | WebGL MSDF text rendering & particle system | Demo | Source |
| Minimal multi-pass / GPGPU example | Demo | Source |
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-texture-paint.jpg) | Interactively drawing to & reading from a WebGL offscreen render texture | Demo | Source |
API
Generated API docs
TODO
Authors
If this project contributes to an academic publication, please cite it as:
@misc{thing-canvas,
title = "@thi.ng/canvas",
author = "Karsten Schmidt",
note = "https://thi.ng/canvas",
year = 2023
}
License
© 2023 - 2024 Karsten Schmidt // Apache License 2.0